Warning: LogicSim 2.6 code resources are not compatible with older versions.of LogicSim .
What is LogicSim SDK 2.6 ?
This software development kit (SDK) allows you to create your own components to add to the list of standard components provided with LogicSim. Of course, modules created by using the "Create module" command are used in exactly the same way as components but with this SDK programmers can write components in Pascal (or C/C++ with more work) and have total control of their behaviour and appearance. Such compnents execute sigificantly faster than modules.
I am only giving general information about the SDK here. The best way to learn how to use it it is to study in detail how the Counter1 example, included with this package, works.
Note: most of the standard LogicSim components, even the ones not in external code resources, use only the API documented here .
Structure of a component
A component manipulates 3 types of objects: the class, symbols and gates.
There is only one class object for a component type, but there may be several instances of symbols or gates.
・ The class contains global data for the component type (typically its picture and its pin descriptions).
・ Symbols are visual representations that are drawn on LogicSim main windows. They also handle mouse clicks during simulation.
・ Gates are logical representations of components. They are created when the simulation is launched (which is sometimes somewhat slow !). They perform all the logical operations.
The component code resource
In concrete terms a code-component is a single code resource (ID = 128, type='PROC') in a resource file (type = 'LSep'). It looks like any CDEF, WDEF or LDEF. At each call the main procedure looks at an integer parameter called "message" and must take the action that is required.
The entry of the code resource must look like:
procedure ComponentProc (var blk: LSBlock);
where blk is a block of parameters.
The message is written in the field 'msg' of the blk record. Not all of the other fields of an LSBlock have a significant meaning for a given message.
Component messages
Class messages
・ msgNewClass
The application sends this message when a new class is loaded. The component proc must describe the component and allocate any global data it needs.
The classDatas field of the structure LSBlock is a Handle which is already allocated. You may want to resize it with SetHandleSize to store in it your class datas. This Handle will be given in the block for any other messages that will be send.
You must supply your class name in the field prmClass^.name and its ID in prmClass^.id. This ID is a variable of type ClassIDType which is a record whith only one field (name). To avoid problems the ID and the name should be equal :
prmClass^.name := myName;
SetClassID(prmClass^.id, myName); { or prmClass^.id.name:= myName }
You give the picture that will be used for displaying the component in the component list (on the left of the window) in prmClass^.image . This is not necessarily the same picture as the one that may be used for drawing in the circuit. If you use a PICT resource don't forget to detach it with DetachResource(Handle(myPicture)) because the file is closed after the msgNewClass message processing.
You specify the pins of your component with the procedure LSDeclarePin:
(pinPos is the position of the pin relative to the component frame, kOutputPin means that it is an output (otherwise use kInputPin), delaysP=nil means that LogicSim will use default delays, and the last parameter is the name of the pin)
・ msgDisposeClass
The component procedure is called with this message when the class is about to be destroyed.
*Don't* dispose of the handle classDatas with Disposehandle ! Since it was allocated by the application, it is destroyed by it too.
Symbol messages
・ msgNewSymbol
This message is sent when a new symbol is created. You can resize the Handle symbolDatas to store any data.
・ msgDisposeSymbol
The message is sent when a symbol is about to be destroyed. As with msgDisposeClass, do NOT DisposeHandle(symbolDatas).
・ msgSimClick
When the user clicks a component during the simulation, LogicSim sends a msgSimClick message to the component procedure. As a result, for instance, the component may change an output value or its appearance.
・ msgDrawSymbol
This message is sent when a symbol must be redrawn. The field prmSymbol^.frame is a Rect that indicates the position of the component. You must draw in the current port. Don't change the clip region or the background colour.
・ msgOptionDialog
・ msgCanOptionDialog
・ msgSetSymbolParams
・ msgGetSymbolParams
Gate messages
・ msgNewGate
・ msgDisposeGate
・ msgReset
・ msgSimulation
・ msgTimer
・ msgGetGateParams
・ msgStimuli
LogicSim procedures for components
Class procedures
procedure LSDeclarePin (env: LSEnvPtr;
classRef: ClassRefT;
loc: Point;
kind: Integer;
delays: DelaysPtr;
name: Str63);
Describes a new pin.
env is a block of pointers to LogicSim internal procedures.
classRef is the reference of the component class.
loc is the position of the pin relative to the component symbol frame.
kind indicates whether the pin is an input (kInputPin) or an output (kOutputPin).
delays is a pointer to a structure that contains 6 delays (of real type Extended). You should use NIL (i.e. default delays).
name is name of the pin. It is not used in the current version of LogicSim (2.6).
Symbol procedures
procedure LSInvalSymbol (env: LSEnvPtr;
symbolRef: SymbolRefT);
Tell LogicSim that it must redraw a component symbol. To redraw a symbol you cannot simply call the component procedure because the port is not ready.
env is a block of pointers to LogicSim internal procedures.
symbolRef is the reference of the symbol to be redrawn.
procedure LSLoop (env: LSEnvPtr;
symbolRef: SymbolRefT);
Tell LogicSim to do normal event processing. This call is only useful in special cases, for example when you are waiting for a "mouse up" after having received a msgSimClick message (that's what the standard component "button" does).
env is a block of pointers to LogicSim internal procedures.
symbolRef is the reference of the symbol that has received the mouse click.
Gate procedures
procedure LSGetInput (env: LSEnvPtr;
gateRef: GateRefT;
pin: Integer;
var value: SValue);
procedure LSSetOutput (env: LSEnvPtr;
gateRef: GateRefT;
pin: Integer;
value: SValue);
procedure LSForceGateSim (env: LSEnvPtr;
gateRef: GateRefT);
procedure LSAddTimer (env: LSEnvPtr;
gateRef: GateRefT;
date: STime);
procedure LSPrintMsg (env: LSEnvPtr;
symOrGate: univ Ptr;
theMessage: Str255);
Utilities
function LSStimNewValueCmd (env: LSEnvPtr;
cmd: StringPtr;
var v: SValue): Boolean;
function CompareClassID (id1, id2: ClassIDType): Boolean;
procedure SetClassID (var id: ClassIDType;
s: Str63);
function LogicAND (a, b: SValue): SValue;
function LogicOR (a, b: SValue): SValue;
function LogicNOT (a: SValue): SValue;
function PositiveEdge (oldV, newV: SValue): Boolean;